package com.gxa.modules.pc.fee.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.utils.PageUtils;
import com.gxa.modules.app.hospitalization.persional.mapper.PatientMapper;
import com.gxa.modules.model.dto.DetailInfoDto;
import com.gxa.modules.model.dto.RechargeDetailRecordDto;
import com.gxa.modules.model.dto.RefundSearchDto;
import com.gxa.modules.model.entity.fee.InpatientRechargeRecords;
import com.gxa.modules.model.entity.fee.Patient;
import com.gxa.modules.model.entity.fee.RechargeOrderDetail;
import com.gxa.modules.pc.fee.mapper.InpatientDetailMapper;
import com.gxa.modules.pc.fee.mapper.InpatientRechargeRecordsMapper;
import com.gxa.modules.pc.fee.mapper.RechargeOrderDetailMapper;
import com.gxa.modules.pc.fee.service.InpatientRechargeRecordsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 住院充值记录表 服务实现类
 * </p>
 *
 * @author gxa
 * @since 2022-11-12 05:31:54
 */
@Service
@Slf4j
public class InpatientRechargeRecordsServiceImpl extends ServiceImpl<InpatientRechargeRecordsMapper, InpatientRechargeRecords> implements InpatientRechargeRecordsService {
    @Autowired
    private InpatientRechargeRecordsMapper inpatientRechargeRecordsMapper;

    @Autowired
    private PatientMapper patientMapper;

    @Autowired
    private RechargeOrderDetailMapper rechargeOrderDetailMapper;

    @Autowired
    private InpatientDetailMapper inpatientDetailMapper;

    @Override
    public PageUtils queryListSearch(RefundSearchDto refundSearchDto) {
        Integer pageSize = refundSearchDto.getPageSize();
        Integer pageNum1 = refundSearchDto.getPageNum();

        Integer pageNum2 = (pageNum1-1)*pageSize;
        log.info("---------{}--", pageNum2);
        refundSearchDto.setPageNum(pageNum2);
        List<RechargeDetailRecordDto> rechargeDetailRecordDtoList = this.inpatientRechargeRecordsMapper.queryListSearch(refundSearchDto);
        Integer count = this.inpatientRechargeRecordsMapper.count(refundSearchDto);
        PageUtils pageUtils = new PageUtils(rechargeDetailRecordDtoList, count, pageSize, pageNum1);
        return pageUtils;
    }

    @Override
    public Map<String, Object> queryInfo(Integer patientId, Integer inInfoId, Integer rechargeOrderId) {
        Map<String,Object> map = new HashMap<>();
        Patient patient = this.patientMapper.queryById(patientId);
        map.put("patient",patient);
        DetailInfoDto detailInfoDto = this.inpatientDetailMapper.queryById(inInfoId);
        System.out.println(detailInfoDto);
        map.put("inpatientDetail",detailInfoDto);
        RechargeOrderDetail rechargeOrderDetail = this.rechargeOrderDetailMapper.queryById(rechargeOrderId);
        map.put("rechargeOrderDetail",rechargeOrderDetail);
        return map;
    }

    @Override
    public List<RechargeDetailRecordDto> queryList() {
        List<RechargeDetailRecordDto> rechargeDetailRecordDtoList = this.inpatientRechargeRecordsMapper.queryList();
        return rechargeDetailRecordDtoList;
    }
}
